package com.tma.mobilechart;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.tma.mobilechart.line.LineInputData;
import com.tma.mobilechart.line.LineItem;
import com.tma.mobilechart.line.LineRender2D;
import com.tma.mobilechart.line.LineRender3D;


public class RenderLineActivity extends Activity {
    /** Called when the activity is first created. */
	
	public static Bitmap mChart;	
	public static String pathChart;
	
	private float x1,x2;
	private Activity activity;
	private Intent localIntent;
	
	private LineRender3D mRenderer3D;
	private LineRender2D mRenderer2D;
	private LineInputData mData;
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // requesting to turn the title OFF
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // making it full screen
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        			 WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        mData = new LineInputData();
        float data1[] = {104, 302, 2076, 404, 1543};
        float data2[] = {170, 250, 545, 123};
        LineItem item = new LineItem(data1.length);
        item.setlYValue(data1);
        item.setlColor(0xFFFF0000);
        //item.
        
        mData.setlData(item);
        LineItem item1 = new LineItem(data2.length);
        item1.setlYValue(data2);
        item1.setlColor(0xFFFF00FF);
        mData.setlData(item1);
        
        // get data from LineChartActivity
        localIntent = getIntent();
        Bundle dataBundle = localIntent.getExtras();
        mData.setL3DStatus(dataBundle.getBoolean("3DStatus"));
        
        //float[] test = mData.getlData().get(0).getlYValue();
        //float[] test1 = mData.getlData().get(1).getlYValue();
        // Initiate the Open GL view and
        // create an instance with this activity  
        
        if (mData.isL3DStatus()) {
	        mRenderer3D = new LineRender3D(this, mData);
	        setContentView(mRenderer3D);
        } else {
        	mRenderer2D = new LineRender2D(this, mData);
	        setContentView(mRenderer2D);
        }
    }
    
    /*@Override
    public boolean onTouchEvent(MotionEvent event) {
	     // TODO Auto-generated method stub      
	    
	     int action = event.getAction();
	     switch(action){
	     	case MotionEvent.ACTION_DOWN:       		
	     		x1 = event.getX();
	     		break;
	     	case MotionEvent.ACTION_MOVE:       		
	     		break;
	     	case MotionEvent.ACTION_UP: 
	     		x2 = event.getX();
	     		if(Math.abs(x1 - x2)>100)
	     		{
	     			mChart = ScreenShot.takeScreenShot(activity);
	     			pathChart = ScreenShot.savePic(mChart);
	     			Intent myintent = new Intent(getApplicationContext(), ShareActivity.class);
	    			startActivityForResult(myintent,0);
	     		}
	     		break;
	     	case MotionEvent.ACTION_CANCEL:     
	     		break;
	     	case MotionEvent.ACTION_OUTSIDE:     
	     		break;
	     	default:
	     		break;
	     	}
	     return true; //processed
    }  */    
     
}